<template>
    <!-- 单证管理 -->
    <div>
      <el-container>
         <el-header style="padding: 0px;display:flex;justify-content:space-between;align-items: center">
          <div style="display: inline">
            <el-input
            placeholder="请输入产品编号"
            clearable
            style="width: 200px;margin: 0px;padding: 0px;"
            size="mini"
            :disabled="advanceSearchViewVisible"
            @keyup.enter.native="searchEmp"
            prefix-icon="el-icon-search"
            v-model="productNo">
            </el-input>
            <el-button type="primary" size="mini" style="margin-left: 5px"
              icon="el-icon-search" @click="searchEmp" :disabled="advanceSearchViewVisible">搜索
            </el-button>
            <el-button slot="reference" type="primary" size="mini" style="margin-left: 5px"
              @click="showAdvanceSearchView">
              <i class="fa fa-lg" v-bind:class="[advanceSearchViewVisible ? faangledoubleup:faangledoubledown]"
                style="margin-right: 5px"></i>高级搜索
            </el-button>
          </div>
          <div style="margin-left: 5px;margin-right: 20px;display: inline">
              <el-button type="success" size="mini"  v-if="cmRole" @click="uploadShow=true">
                  <i class="el-icon-upload2"></i>
                  导入单证信息
              </el-button>
            <el-button type="success" size="mini" @click="exportInfo"  :disabled="exportLoading" :loading="exportLoading"  v-if="cmRole"  style="margin:0 10px">
                <i class="el-icon-download"></i>
                导出单证信息
            </el-button>
            <el-button type="success" size="mini" @click="allotEmps('00')"  v-if="cmRole">
                <i class="el-icon-sold-out" style="margin-right: 5px"></i>
                单证管理员分配合同
            </el-button>
            <el-button type="success" size="mini" @click="allotEmps('01')"  v-if="inputRole">
                <i class="el-icon-sold-out" style="margin-right: 5px"></i>
                初审分配合同
            </el-button>
            <el-button type="primary" size="mini" icon="el-icon-plus" v-if="cmRole" @click="addContract">
                生成合同
            </el-button>
          </div>
         </el-header>
        <el-main>
          <!-- 高级搜索 -->
          <div>
            <transition name="el-fade-in-linear">
              <div v-show="advanceSearchViewVisible" class="seniorModel"> 
                  <el-row>
                    <el-col :span="8">
                      <span>产品编号:</span>  
                      <el-input
                        class="seniorInput"
                        placeholder="请输入产品编号"
                        v-model="productNo"
                        clearable>
                      </el-input>
                    </el-col>
                    <el-col :span="8" v-if="!inputRole">
                      <span>网点:</span>  
                      <el-input
                        class="seniorInput"
                        placeholder="请输入网点"
                        v-model="department"
                        clearable>
                      </el-input>
                    </el-col>
                    <el-col :span="8">
                      <span>合同编号:</span>  
                      <el-input
                        class="seniorInput"
                        placeholder="请输入合同编号"
                        v-model="contractNo"
                        clearable>
                      </el-input>
                    </el-col>
                  </el-row>
                  <el-row>
                    <el-col :span="6">
                      <span>所有人:</span>  
                      <el-input
                        class="seniorInput"
                        placeholder="请输入所有人"
                        v-model="ownerName"
                        clearable>
                      </el-input>
                    </el-col>
                    <el-col :span="6">
                      <span>使用人:</span>  
                      <el-input
                        placeholder="请输入使用人"
                        class="seniorInput"
                        v-model="userName"
                        clearable>
                      </el-input>
                    </el-col>
                    <el-col :span="6">
                      <span>是否使用:</span>  
                      <el-radio v-model="isUse" :label="true">是</el-radio>
                      <el-radio v-model="isUse" :label="false">否</el-radio>
                    </el-col>
                    <el-col :span="6">
                      <span>是否分配:</span>  
                      <el-radio v-model="isAssigned" :label="true">是</el-radio>
                      <el-radio v-model="isAssigned" :label="false">否</el-radio>
                    </el-col>
                  </el-row>
                  <el-row>
                    <el-col align="left">
                      <el-button icon="el-icon-search" type="primary" size="mini" @click="search">搜索</el-button>
                      <el-button size="mini" @click="cancelSearch">取消</el-button>
                    </el-col>
                  </el-row>  
              </div>
            </transition>
          </div>
          <!-- 表单列表 -->
          <div>
            <el-table
              :data="table"
              v-loading="tableLoading"
              border
              stripe 
              size="mini"
              height="500"
              style="width: 100%">
              <el-table-column
                align="center"
                prop="productNo"
                label="产品编号"
                fixed
                width="200">
              </el-table-column>
              <el-table-column
                width="200"
                align="center"
                label="合同编号"
                fixed
                prop="contractNo">
              </el-table-column>
              <el-table-column
                label="所有人"
                prop="ownerName"
                align="center"
                fixed
                width="120">
              </el-table-column>
              <el-table-column
                width="120"
                align="center"
                fixed
                label="使用人"
                prop="userName">
              </el-table-column>
              <el-table-column
                width="95"
                align="center"
                label="网点"
                prop="department">
              </el-table-column>
              <el-table-column
                width="95"
                align="center"
                label="组"
                prop="group">
              </el-table-column>
              <el-table-column
                width="95"
                align="center"
                label="部"
                prop="part">
              </el-table-column>
              <el-table-column
                width="95"
                align="center"
                label="区"
                prop="area">
              </el-table-column>  
              <el-table-column
                width="100"
                align="center"
                label="是否使用"
                >
                <template slot-scope="scope">
                  {{scope.row.isUse?'是':'否'}}
                </template>
              </el-table-column>
              <el-table-column
                width="200"
                align="center"
                label="使用时间"
                prop="useTime">
              </el-table-column>
              <el-table-column
                width="100"
                label="是否分配"
                align="center"
                >
                <template slot-scope="scope">
                  {{scope.row.isAssigned?'是':'否'}}
                </template>
              </el-table-column>
              <el-table-column
                label="分配时间"
                width="200"
                align="center"
                prop="assignedTime">
              </el-table-column>
              <el-table-column
                fixed="right"
                align="center"
                label="操作"
                width="200">
                <template slot-scope="scope">
                  <el-button type="primary" size="mini" style="padding: 8px;margin: 2px" 
                  v-if="cmRole&&scope.row.isUse==false" @click="secondAssign(scope.row)">重新分配</el-button>
                  <el-button style="padding: 8px;margin: 2px" type="danger"
                            size="mini" @click="scrapItem(scope.row)" :disabled="scope.row.isDelate==true?true:false">作废
                  </el-button>
                </template>
              </el-table-column>
            </el-table>
            <el-pagination
                background
                :page-size="pageSize"
                :current-page="currentPage"
                @current-change="currentChange"
                layout="prev, pager, next"
                :total="totalCount"
                style="margin:50px;">
            </el-pagination>
            <div style="margin:30px 0;" class="fw">共{{Math.ceil(totalCount/pageSize)}}页,{{totalCount}}条信息</div>
          </div>
        </el-main>
          <div class="dialog">
            <!-- 生成合同 -->
            <template>
              <el-dialog title="生成合同" :visible.sync="dialogFormVisible" 
                v-loading="dialogLoading"
                :close-on-click-modal="false"
                width="800px">
                <el-form :model="form"  ref="form">
                  <el-row>
                    <el-col :span="1"></el-col>
                    <el-col :span="16" align="left">
                      <span>产品名称或编号:</span>
                      <el-select
                            v-model="form.productName"
                            filterable
                            remote
                            placeholder="请输入产品名称或编号"
                            :remote-method="inputProductNameMethod"
                            :loading="inputProductNameLoading"
                            @change="productNameChange" clearable>
                            <el-option
                              v-for="item in inputProductNameArray"
                              :key="item.productId"
                              :label="item.productName"
                              :value="item.productName">
                            </el-option>
                      </el-select>
                    </el-col>
                    <el-col :span="7" align="left">
                      已分配{{form.contractNoMax}}份，剩余{{form.createContractNumMax}}份可分配
                    </el-col>
                  </el-row>
                  <el-row>
                    <el-col :span="1"></el-col>
                    <el-col :span="23" align="left">
                      <span>生成合同份数：</span>
                      <el-input v-model="form.number" type="number" placeholder="请输入要生成合同份数"
                      clearable></el-input>
                    </el-col>
                  </el-row>
                  <el-row>
                      <el-col :span="14"></el-col>
                      <el-col :span="8" align="right">
                          <el-button type="primary" @click="sureAdd">生成</el-button>
                          <el-button @click="dialogFormVisible=false;">取消</el-button>
                      </el-col>
                      <el-col :span="2"></el-col>
                  </el-row>
                </el-form>
              </el-dialog>
            </template>
            <!-- 分配合同 -->
            <template>
              <el-dialog title="分配合同" :visible.sync="dialogForm2Visible" 
                v-loading="dialogLoading"
                :close-on-click-modal="false"
                width="800px">
                <el-form :model="form2">
                  <el-row>
                    <el-col :span="1"></el-col>
                    <el-col :span="16" align="left">
                      <span>产品编号:</span>
                      <el-select
                            v-model="form2.productNo"
                            filterable
                            remote
                            placeholder="请输入产品编号"
                            :remote-method="inputProductNoMethod"
                            :loading="inputProductNoLoading"
                            @change="productNoChange" clearable>
                            <el-option
                              v-for="item in inputProductNoArray"
                              :key="item.productId"
                              :label="item.productNo"
                              :value="item.productNo">
                            </el-option>
                      </el-select>
                    </el-col>
                    <el-col :span="7" align="left">
                      已分配{{form2.contractNoMax}}份，剩余{{form2.createContractNumMax}}份可分配
                    </el-col>
                  </el-row>
                  <el-row>
                    <el-col :span="1"></el-col>
                    <el-col :span="23" align="left">
                      <span>分配合同编号范围：</span>
                      <el-input v-model="form2.startNo" type="number" placeholder="开始编号"
                      clearable style="width:150px;"></el-input> ----
                      <el-input v-model="form2.endNo" type="number" placeholder="结束编号"
                      clearable style="width:150px;"></el-input>
                    </el-col>
                  </el-row>
                  <el-row v-if="allotRole=='00'">
                    <el-col :span="1"></el-col>
                    <el-col :span="23" align="left">
                      <span>选择部门：</span>
                      <el-select v-model="form2.department" placeholder="请选择部门">
                        <el-option
                          v-for="item in form2.departmentArray"
                          :key="item.value"
                          :label="item.label"
                          :value="item.value">
                        </el-option>
                      </el-select>
                    </el-col>
                  </el-row>
                  <el-row v-if="allotRole=='01'">
                    <el-col :span="1"></el-col>
                    <el-col :span="23" align="left">
                      <span>选择服务人员：</span>
                      <el-select v-model="form2.salemanName" placeholder="请选择服务人员" 
                        filterable @change="salemanNameChange" clearable>
                        <el-option
                          v-for="item in form2.salemanArray"
                          :key="item.salemanId"
                          :label="item.salemanName"
                          :value="item.salemanName"
                          data-id="item.id"
                          ref="saleman">
                        </el-option>
                      </el-select> 
                    </el-col>
                  </el-row>
                  <el-row>
                      <el-col :span="14"></el-col>
                      <el-col :span="8" align="right">
                          <el-button type="primary" @click="sureAllot">分配</el-button>
                          <el-button @click="dialogForm2Visible=false;">取消</el-button>
                      </el-col>
                      <el-col :span="2"></el-col>
                  </el-row>
                </el-form>
              </el-dialog>
            </template>
            <!-- 导入单证 -->
            <template>
              <el-dialog title="导入单证" :visible.sync="uploadShow" 
                v-loading="uploadLoding"
                :close-on-click-modal="false"
                width="600px">
                <el-form>
                  <el-row>
                    <el-col :span="1"></el-col>
                    <el-col :span="23" align="left">
                      <span>产品名称或编号:</span>
                      <el-select
                            v-model="form.productName"
                            filterable
                            remote
                            placeholder="请输入产品名称或编号"
                            :remote-method="inputProductNameMethod"
                            :loading="inputProductNameLoading"
                            @change="productNameChange" clearable>
                            <el-option
                              v-for="item in inputProductNameArray"
                              :key="item.productId"
                              :label="item.productName"
                              :value="item.productName">
                            </el-option>
                      </el-select>
                    </el-col>
                  </el-row>
                  <el-row>
                    <el-col :span="18"></el-col>
                    <el-col :span="6">
                      <el-upload
                      class="upload-demo fl"
                      action="/contract_no/importCustomerInfo"
                      :data="uploadData"
                      :disabled="uploadLoding"
                      :show-file-list="false"
                      :before-upload="beforeUpload"
                      :on-change="uploadChange"
                      :on-success="uploadSuccess"
                      :on-error="uploadError">
                        <el-button size="small" type="primary">点击导入</el-button>
                      </el-upload>
                    </el-col>
                  </el-row>
                </el-form>
              </el-dialog>
            </template>
            <!-- 二次分配 -->
            <template>
              <el-dialog title="二次分配" :visible.sync="secondAssignVisible" 
                v-loading="dialogLoading"
                :close-on-click-modal="false"
                width="800px">
                <el-form>
                  <el-row>
                    <el-col :span="1"></el-col>
                    <el-col :span="23" align="left">
                      <span>选择部门：</span>
                      <el-select v-model="form2.department" placeholder="请选择部门">
                        <el-option
                          v-for="item in form2.departmentArray"
                          :key="item.value"
                          :label="item.label"
                          :value="item.value">
                        </el-option>
                      </el-select>
                    </el-col>
                  </el-row>
                  <el-row>
                      <el-col :span="14"></el-col>
                      <el-col :span="8" align="right">
                          <el-button type="primary" @click="sureSecondAssign">分配</el-button>
                          <el-button @click="secondAssignVisible=false;">取消</el-button>
                      </el-col>
                      <el-col :span="2"></el-col>
                  </el-row>
                </el-form>
              </el-dialog>
            </template>
          </div>
      </el-container>
    </div>
</template>
<script>
var productId = -1;
var salemanId = -1;
var secondAssignContractNo=""
var searchInfo={
  contractNo:"",
  productNo:"",
  ownerName:"",
  userName:"",
  isUse:false,
  isAssigned:false,
  department:"",
};
export default {
  data() {
    return {
      exportLoading:false,
      inputRole: false,
      cmRole: false,
      uploadLoding:false,
      uploadShow:false,
      uploadData:{
        productId:''
      },
      allotRole: "",
      productNo: "",
      department:"",
      contractNo:"",
      ownerName:"",
      userName:"",
      isUse:false,
      isAssigned:false,
      saleman: "",
      advanceSearchViewVisible: false,
      faangledoubleup: "fa-angle-double-up",
      faangledoubledown: "fa-angle-double-down",
      dialogFormVisible: false,
      inputProductNameLoading: false,
      dialogLoading: false,
      inputProductNameArray: [],
      dialogForm2Visible:false,
      inputProductNoLoading:false,
      secondAssignVisible:false,
      inputProductNoArray:[],
      birthdayOptions: {
        disabledDate(time) {
          return time.getTime() > Date.now();
        }
      },
      form: {
        productName: "",
        number: "",
        contractNoMax: 0,
        createContractNumMax: 0,
      },
      form2: {
        productNo: "",
        startNo:"",
        endNo:"",
        department: "",
        departmentArray: [],
        salemanName:"",
        salemanArray:[],
        createContractNumMax: 0,
        contractNoMax: 0,
      },
      table: [],
      tableLoading: false,
      currentPage: 1,
      pageSize: 20,
      totalCount: 0,
      tableSearchModel: "common"
    };
  },
  mounted() {
    this.getRequest("/common/getDepartmentInfo").then(resp =>{
      if(resp && resp.status==200){
          this.form2.departmentArray=resp.data.obj.departmentList;
      }
    })
    this.getRequest("/common/user/id/" + this.$store.state.user.id).then(
      resp => {
        if (resp && resp.status == 200) {
          for (var i = 0; i < resp.data.roles.length; i++) {
            if (resp.data.roles[i].nameZh == "初审") {
              this.inputRole = true;
            }
            if (resp.data.roles[i].nameZh == "单证管理员" || resp.data.roles[i].nameZh == "系统管理员") {
              this.cmRole = true;
            }
          }
        }
      }
    );
    this.initData();
  },
  methods: {
    initData: function() {
      this.requestTableInfo(
        this.tableSearchModel,
        this.currentPage,
        this.pageSize
      );
    },
    // 请求列表数据
    requestTableInfo: function(model, pageCount, pageSize) {
      var that = this;
      //根据合同编号搜查的普通模式
      if (model == "common") {
        that.tableLoading = true;
        that
          .postRequest("/contract_no/mg", {
            productNo: that.productNo,
            pageIndex: pageCount,
            pageSize: pageSize
          })
          .then(resp => {
            that.tableLoading = false;
            if (resp && resp.data.status == 200) {
              that.table = resp.data.obj.rows;
              that.totalCount = resp.data.obj.total;
              searchInfo={
                contractNo:"",
                productNo:that.productNo,
                ownerName:"",
                userName:"",
                isUse:"",
                isAssigned:"",
                department:"",
              };
            }
          });
      } else if (model == "senior") {
        //高级搜索模式
        that.tableLoading = true;
        that
          .postRequest("/contract_no/mg", {
            productNo:that.productNo,
            department:that.department,
            contractNo:that.contractNo,
            ownerName:that.ownerName,
            userName:that.userName,
            isUse:that.isUse,
            isAssigned:that.isAssigned,
            pageIndex: pageCount,
            pageSize: pageSize
          })
          .then(resp => {
            that.tableLoading = false;
            if (resp && resp.data.status == 200) {
              that.table = resp.data.obj.rows;
              that.totalCount = resp.data.obj.total;
              searchInfo={
                contractNo:that.contractNo,
                productNo:that.productNo,
                ownerName:that.ownerName,
                userName:that.userName,
                isUse:that.isUse,
                isAssigned:that.isAssigned,
                department:that.department,
              };
            }
          });
      }
    },
    //列表当前页改变
    currentChange: function(currentChange) {
      this.currentPage = currentChange;
      this.requestTableInfo(
        this.tableSearchModel,
        this.currentPage,
        this.pageSize
      );
    },
    // 点击高级搜索
    showAdvanceSearchView() {
      this.advanceSearchViewVisible = !this.advanceSearchViewVisible;
      this.productNo = "";
      if (this.tableSearchModel == "common") {
        this.tableSearchModel = "senior";
      } else if (this.tableSearchModel == "senior") {
        this.tableSearchModel = "common";
      }
    },
    //取消高级搜索
    cancelSearch: function() {
      this.advanceSearchViewVisible = false;
      this.tableSearchModel = "common";
    },
    // 普通搜索
    searchEmp: function() {
      this.currentPage = 1;
      this.requestTableInfo(
        this.tableSearchModel,
        this.currentPage,
        this.pageSize
      );
    },
    //高级搜索
    search: function() {
      this.currentPage = 1;
      this.requestTableInfo(
        this.tableSearchModel,
        this.currentPage,
        this.pageSize
      );
    },
    //生成合同
    addContract() {
      this.dialogFormVisible = true;
    },
    // 分配合同
    allotEmps: function(role) {
      this.dialogForm2Visible = true;
      this.allotRole = role;
      if(role=='01'){
        this.postRequest('/contract_no/get_sale_info').then(resp =>{
          if(resp && resp.data.status==200){
            this.form2.salemanArray=resp.data.obj;
          }
        })
      }
    },
    //二次分配
    secondAssign(item){
      secondAssignContractNo=item.contractNo;
      this.secondAssignVisible=true;
      this.form2.department=item.department;
    },
    //确认二次分配
    sureSecondAssign(){
      this.dialogLoading=true;
      this.putRequest("/contract_no/second_assign_admin", {
            contractNo: secondAssignContractNo,
            department:this.form2.department,
          }).then(resp => {
            this.dialogLoading = false;
            if (resp && resp.data.status == 200) {
              this.secondAssignVisible=false;
              this.form2.department = "";
              this.common.showToast("success", resp.data.msg);
              this.initData();
            }
          });
    },
    // 输入产品名称
    inputProductNameMethod: function(query) {
  
        if (query !== "") {
          this.inputProductNameLoading = true;
          this.postRequest("/common/get_product_info", {
            searchContent: query
          }).then(resp => {
            if (resp && resp.data.status == 200) {
              this.inputProductNameArray = resp.data.obj;
            }
            this.inputProductNameLoading = false;
          });
        } else {
          this.inputProductNameArray = [];
        }
      
    },
    // 产品名称发生变化
    productNameChange: function(e) {
      var that = this;
      if (e == "") {
        productId = -1;
        this.form.contractNoMax = 0;
        this.form.createContractNumMax = 0;
      } else {
        this.postRequest("/common/get_product_info", {
          searchContent: e
        }).then(resp => {
          if (resp && resp.data.status == 200) {
            productId = resp.data.obj[0].productId;
            this.form.contractNoMax = resp.data.obj[0].contractNoMax;
            this.form.createContractNumMax =resp.data.obj[0].createContractNumMax;
          }
        });
      }
    },
    //确定生成合同
    sureAdd: function() {
      var that = this;
        if (
          this.common.isNull(this.form.productName) ||
          this.form.productName == null
        ) {
          this.common.showToast("info", "请输入产品名称");
        } else if (
          this.common.isNull(this.form.number) ||
          this.form.number == null
        ) {
          this.common.showToast("info", "请输入生成数量");
        } else {
          this.dialogLoading = true;
          this.putRequest("/contract_no/create_contact_no", {
            productId: productId,
            contractNum: this.form.number
          }).then(resp => {
            that.dialogLoading = false;
            if (resp && resp.data.status == 200) {
              that.dialogFormVisible = false;
              this.form.productName = "";
              this.form.number = "";
              that.common.showToast("success", resp.data.msg);
              this.initData();
            }
          });
        }
      
    },
    //报废单证
    scrapItem(item) {
      this.$confirm("此操作将作废该单证, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      })
        .then(() => {
          this.putRequest("/contract_no/delete_contract_no", {
            contractNo: item.contractNo
          }).then(resp => {
            if (resp && resp.data.status == 200) {
              this.common.showToast("success", resp.data.msg);
              this.initData();
            }
          });
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消"
          });
        });
    },
    // 输入产品编号
    inputProductNoMethod: function(query) {
        if (query !== "") {
          this.inputProductNoLoading = true;
          this.postRequest("/contract_no/get_product_info", {
            searchContent: query,
            role:this.allotRole,
          }).then(resp => {
            if (resp && resp.data.status == 200) {
              this.inputProductNoArray = resp.data.obj;
            }
            this.inputProductNoLoading = false;
          });
        } else {
          this.inputProductNoArray = [];
        }
      
    },
    // 产品编号发生变化
    productNoChange: function(e) {
      var that = this;
      if (e == "") {
        this.form2.contractNoMax = 0;
        this.form2.createContractNumMax = 0;
      } else {
        this.postRequest("/contract_no/get_product_info", {
          searchContent: e,
          role:this.allotRole,
        }).then(resp => {
          if (resp && resp.data.status == 200) {
            if(resp.data.obj.length>0){
              this.form2.contractNoMax = resp.data.obj[0].contractNoMax;
              this.form2.createContractNumMax =resp.data.obj[0].createContractNumMax;
            }else{
              this.form2.contractNoMax = 0;
              this.form2.createContractNumMax = 0;
            }
          }
        });
      }
    },
    //服务人员改变
    salemanNameChange(name){
      if(name==""){
        salemanId=-1;
      }else{
        var obj = {};
        obj = this.form2.salemanArray.find((item)=>{
            return item.salemanName === name;
        });
        salemanId=obj.salemanId;
      }
      
    },
    //确认分配
    sureAllot(){
      // 管理员
      if(this.allotRole=='00'){
        if(this.form2.productNo==(null || "")){
          this.common.showToast("info",'请输入产品编号')
        }else if(this.form2.startNo==(null || "")){
          this.common.showToast("info",'请输入开始编号')
        }
        else if(this.form2.endNo==(null || "")){
          this.common.showToast("info",'请输入结束编号')
        }
        else if(this.form2.department==(null || "")){
          this.common.showToast("info",'请选择部门')
        }else{
          this.dialogLoading=true;
          this.putRequest("/contract_no/assign_admin", {
            productNo: this.form2.productNo,
            startNo:this.form2.startNo,
            endNo:this.form2.endNo,
            department: this.form2.department,
          }).then(resp => {
            this.dialogLoading = false;
            if (resp && resp.data.status == 200) {
              this.dialogForm2Visible=false;
              this.form2.productNo = "";
              this.form2.startNo = "";
              this.form2.endNo = "";
              this.form2.department = "";
              this.form2.createContractNumMax = 0;
              this.form2.contractNoMax = 0;
              this.common.showToast("success", resp.data.msg);
              this.initData();
            }
          });
        }
      }else if(this.allotRole=='01'){
        if(this.form2.productNo==(null || "")){
          this.common.showToast("info",'请输入产品编号')
        }else if(this.form2.startNo==(null || "")){
          this.common.showToast("info",'请输入开始编号')
        }
        else if(this.form2.endNo==(null || "")){
          this.common.showToast("info",'请输入结束编号')
        }
        else if(this.form2.salemanName==(null || "")){
          this.common.showToast("info",'请选择服务人员')
        }else{
          this.dialogLoading=true;
          this.putRequest("/contract_no/assign_input", {
            productNo: this.form2.productNo,
            startNo:this.form2.startNo,
            endNo:this.form2.endNo,
            ownerId: salemanId,
          }).then(resp => {
            this.dialogLoading = false;
            if (resp && resp.data.status == 200) {
              this.dialogForm2Visible=false;
              this.form2.productNo = "";
              this.form2.startNo = "";
              this.form2.endNo = "";
              this.form2.salemanName = "";
              salemanId=-1;
              this.form2.createContractNumMax = 0;
              this.form2.contractNoMax = 0;
              this.common.showToast("success", resp.data.msg);
              this.initData();
            }
          });
        }
      }
    },
    //导出信息
    exportInfo(){ 
      this.exportLoading = true ;
      var address=`/contract_no/contract_no_export?contractNo=${searchInfo.contractNo}&&productNo=${searchInfo.productNo}&&ownerName=${searchInfo.ownerName}&&userName=${searchInfo.userName}&&department=${searchInfo.department}&&isUse=${searchInfo.isUse}&&isAssigned=${searchInfo.isAssigned}`
      // this.common.downloadFile(address); 
      this.common.downloadFile(address)
      setTimeout(() => {
        this.exportLoading =false;
      }, 2000);
    },
    //上传前判断
    beforeUpload(file){
        var testmsg=file.name.substring(file.name.lastIndexOf('.')+1)				
				const extension = testmsg === 'xls'
        const extension2 = testmsg === 'xlsx'
        const isLt10M = file.size / 1024 / 1024 < 10
        const hasId=productId!=-1;
        if(!hasId){
          this.common.showToast('warning','请选择产品')
          this.uploadLoding=false;
        }
        if(hasId){
          this.uploadData.productId=productId
        }
        if(!extension && !extension2) {
          this.common.showToast('warning','上传文件只能是 xls、xlsx格式!')
          this.uploadLoding=false;
        }
        if(!isLt10M) {
          this.common.showToast('warning','上传文件大小不能超过 10MB!')
          this.uploadLoding=false;
        }
        return extension || extension2 && isLt10M && hasId
    },
    upLoad(item){
      this.uploadFileRequest("/contract_no/importCustomerInfo",{
        file:item,
        productId:productId,
      }).then(resp =>{
        this.uploadLoding=false;
        if(resp && resp.data.status==200){
          this.common.showToast('success',response.msg)
          this.currentPage = 1;
            this.requestTableInfo(
            this.tableSearchModel,
            this.currentPage,
            this.pageSize
          );
        }
      })
    },
    // 上传文件改变
    uploadChange(file,fileList){
      this.uploadLoding=!this.uploadLoding
    },
    uploadSuccess(response,file,fileList){
      if(response.status==200){
        this.common.showToast('success',response.msg)
        this.uploadShow=false;
        this.currentPage = 1;
        this.requestTableInfo(
          this.tableSearchModel,
          this.currentPage,
          this.pageSize
        );
      }else{
        this.common.showToast('warning',response.msg)
      }
    },
    uploadError(response,file,fileList){
      // this.common.showToast('error','上传失败')
    },
  }
};
</script>
<style scoped>
.el-row {
  margin-bottom: 30px;
  height: 50px;
  line-height: 50px;
}
.el-col {
  height: 50px;
  line-height: 50px;
}
.seniorModel{
  margin-bottom: 10px;
  border: 1px;
  border-radius: 5px;
  border-style: solid;
  padding: 10px;
  box-sizing:border-box;
  border-color: #20a0ff
}
.seniorModel .el-row{
  text-align: left;
}
.seniorInput{
  width: 50%;
}
.dialog .el-input{
  width: 300px;
}
.dialog .el-select{
  width: 300px;
}
</style>    